<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="">
    <meta http-equiv="x-dns-prefetch-control" content="on">

    <title>首页</title>
    <link href="../css/css.css" rel="stylesheet" type="text/css">
    <script src="../js/jquery-v1.11.2.min.js"></script>
    <script src="../js/common.js"></script>
    <script src="../js/driver.js"></script>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=4082cc7cea44a1f8c926676ce9508fac&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.Geocoder"></script>
</head>
<body>
<section class="slider_inner">
    <div class="slider_dot">
        <div class="dot_checked w_checked"></div>
        <div class="dot_none w_none"></div>
        <div class="dot_none w_none"></div>
        <div class="dot_none w_none"></div>
        <div class="dot_none w_none"></div>
    </div>
    <div class="slider_item"><img src="../img/banner.png"/></div>
</section>
<section class="pall15" style="overflow: hidden;">
    <div class="home_button mr4p" onclick="bid()">
        <label class="hometext">抢单</label>
        <i class="iconfont home_ico">&#xe70f;</i>
    </div>
    <div class="home_button" onclick="order()">
        <label class="hometext">我的订单</label>
        <i class="iconfont home_ico">&#xe710;</i>
    </div>
    <div class="home_button mr4p" id="workStatusDiv">
        <label class="hometext">开始接单</label>
        <i class="iconfont home_ico">&#xe712;</i>
    </div>
    <div class="home_button" onclick="newOrder()">
        <label class="hometext">一键下单</label>
        <!-- <label class="tel">65376537</label> -->
        <i class="iconfont home_ico">&#xe711;</i>
    </div>
</section>
<form id="orderForm" name="orderForm" method="post">
     <input type="hidden" id="vehiclePriceId" name="vehiclePriceId" value=""/>
     <input type="hidden" id="bookDate" name="bookDate" value=""/>
     <input type="hidden" id="consignDesc" name="consignDesc" value=""/>
     <input type="hidden" id="consignName" name="consignName" value=""/>
     <input type="hidden" id="consignMobile" name="consignMobile" value=""/>
     <input type="hidden" id="callType" name="callType" value="NOW"/>
     <input type="hidden" id="addrType" name="addrType" value=""/>
     <input type="hidden" id="waybillRquirement10" name="waybillRquirement10" value=""/>
	 <input type="hidden" id="waybillRquirement20" name="waybillRquirement20" value=""/>
	 <input type="hidden" id="waybillRquirement30" name="waybillRquirement30" value="1"/>

	 <input type="hidden" id="startDistrictCode" name="startDistrictCode" value=""/>
	 <input type="hidden" id="startAddr" name="startAddr" value=""/>
	 <!--startPCD 起点 省市区-->
	 <input type="hidden" id="startPCD" name="startPCD" value=""/>
	 <!-- 起点经纬度 -->
	 <input type="hidden" id="startLocation" name="startLocation" value=""/>
	 
	 <input type="hidden" id="endDistrictCode" name="endDistrictCode" value=""/>
	 <input type="hidden" id="endAddr" name="endAddr" value="目的地址"/>
	 <!--startPCD  省市区-->
	 <input type="hidden" id="endPCD" name="endPCD" value="上海市闵行区"/>
	 <!-- 终点经纬度 -->
	 <input type="hidden" id="endLocation" name="endLocation" value="121.339766,31.196099"/>
	 
	  <!-- 第二终点参数 -->
	 <input type="hidden" id="endDistrictCode1" name="endDistrictCode1" value=""/>
	 <input type="hidden" id="endAddr1" name="endAddr1" value=""/>
	 <!--startPCD  省市区-->
	 <input type="hidden" id="endPCD1" name="endPCD1" value=""/>
	 <!-- 终点经纬度 -->
	 <input type="hidden" id="endLocation1" name="endLocation1" value=""/>
	 
	 <!-- 第三终点参数 -->
	 <input type="hidden" id="endDistrictCode2" name="endDistrictCode2" value=""/>
	 <input type="hidden" id="endAddr2" name="endAddr2" value=""/>
	 <!--startPCD  省市区-->
	 <input type="hidden" id="endPCD2" name="endPCD2" value=""/>
	 <!-- 终点经纬度 -->
	 <input type="hidden" id="endLocation2" name="endLocation2" value=""/>
	 <input type="hidden" id="goodsRemark" name="goodsRemark" value=""/>
	 <input type="hidden" id="goodsType" name="goodsType" value="99"/>
	  <input type="hidden" id="goodsTypeName" name="goodsTypeName" value="其他"/>
	 <input type="hidden" id="consignNum" name="consignNum" value="1"/>
	 <input type="hidden" id="endAddrCount" name="endAddrCount" value="1"/>
	 
	 <input type="hidden" id="planDistance" name="planDistance" value=""/>
	 <input type="hidden" id="planStartFee" name="planStartFee" value=""/>
	 <input type="hidden" id="planExceedFee" name="planExceedFee" value=""/>
	 <input type="hidden" id="planSpecialFee" name="planSpecialFee" value=""/>
	 <input type="hidden" id="planTotalFee" name="planTotalFee" value=""/>
	 <input type="hidden" id="specialFee10" name="specialFee10" value=""/>
	 <input type="hidden" id="specialFee20" name="specialFee20" value=""/>
	 <input type="hidden" id="driverUuid" name="driverUuid" />
	 
	  <input type="hidden" id="startStreet" name="startStreet" />
	 <input type="hidden" id="startCross" name="startCross" />
	 <input type="hidden" id="startDoorNo" name="startDoorNo" />
	 
	 <input type="hidden" id="endStreet" name="endStreet" value="目的地址"/>
	 <input type="hidden" id="endCross" name="endCross" />
	 <input type="hidden" id="endDoorNo" name="endDoorNo" />
	 <input type="hidden" id="acceptPersonMobile" name="acceptPersonMobile" />
	 <input type="hidden" id="acceptPersonName" name="acceptPersonName" />
	 
	  <input type="hidden" id="endStreet1" name="endStreet1" />
	 <input type="hidden" id="endCross1" name="endCross1" />
	 <input type="hidden" id="endDoorNo1" name="endDoorNo1" />
	 <input type="hidden" id="acceptPersonMobile1" name="acceptPersonMobile1" />
	 <input type="hidden" id="acceptPersonName1" name="acceptPersonName1" />
	 
	 <input type="hidden" id="endStreet2" name="endStreet2" />
	 <input type="hidden" id="endCross2" name="endCross2" />
	 <input type="hidden" id="endDoorNo2" name="endDoorNo2" />
	 <input type="hidden" id="acceptPersonMobile2" name="acceptPersonMobile2" />
	 <input type="hidden" id="acceptPersonName2" name="acceptPersonName2" />
	 
	  <input type="hidden" id="planLoadTime" name="planLoadTime" />
	 <input type="hidden" id="planUnloadTime" name="planUnloadTime" />
	 <input type="hidden" id="planLoadFee" name="planLoadFee" />
	 <input type="hidden" id="planUnloadFee" name="planUnloadFee" />
	 <input type="hidden" id="planLowSpeedTime" name="planLowSpeedTime" />
	 <input type="hidden" id="planLowSpeedFee" name="planLowSpeedFee" />
</form>
<script type="text/javascript">
	var isFullCar = "";
    $(function () {
        checkDriverTokenIndex();//token验证
        var driverUuid=getCookie("driverUuid");
    	$("#driverUuid").val(driverUuid);
    	var callType="NOW";
    	
   	    var url = _global.serverHost +"/driverOrder/inputOrder.htm";
   	    var driverUuid=getCookie("driverUuid");
        var data = {
       	'callType':callType,
       	'driverUuid':driverUuid
        };
        _callAjaxRequest(url, data, callBack);
		function callBack(data) {
			//cookie2Order();
			var trackList = data.trackList;
			var endAddrCount = 1;
			isFullCar = data.c3;
			var vehiclePriceId = $("#vehiclePriceId").val();
			console.log("=====vehiclePriceId=" + vehiclePriceId);
			for (var i = 0; i < trackList.length; i++) {
				if (data.vehicleType == trackList[i].vehicleType) {
					$("#vehiclePriceId").val(trackList[i].id);
				}
			}
			var bookDate = $("#bookDate").val();
			
			$("#bookDate").val(data.bookDateHHMM);
		}
		var driverInfo = eval("(" + localStorage.getItem("driverInfo") + ")");
		console.log("====" + JSON.stringify(driverInfo));
		genWorkStatus(driverInfo.lockFlag);
		quickBill();
	});
	function bid() {
		window.location.href = "../driver/bid/bid_list.html";
	}
	function order() {
		window.location.href = "../driver/order/order_list.html";
	}
	function newOrder() {
		//clearOrderCookie();
		//setCookie("callType","NOW");
		//window.location.href = "../driver/order/input_order_now.html";
		if(isFullCar!='00'){
			alert("您现在不在空车状态，不能一键下单！");
			return false;	
		}
		$.ajax({
					type : 'POST',
					url : _global.serverHost + '/driverOrder/saveOrder.htm',
					data : $('#orderForm').serialize(),
					contentType : "application/x-www-form-urlencoded;charset=UTF-8",
					success : function(data) {
						if (data.outResult == '1') {
							//window.location.href="${pageContext.request.contextPath}/consignerOrder/waitOrder.htm?waybillId="+data.waybillId;
							window.location.href = "./start_bid/goon_bid1.html?waybillId="+ data.waybillId;
							//window.location.href="./order_list.html";
						} else {
							alert(data.outResultReason);
						}
					}
				});
	}
	function genWorkStatus(lockFlag) {
		var htmlStr = "";
		if (lockFlag == "0") {
			$("#workStatusDiv").removeClass();
			$("#workStatusDiv").addClass("home_button_stop mr4p");
			htmlStr = '<label class="hometext" onclick="chgWorkStatus(1);">停止接单</label><i onclick="chgWorkStatus(1);" class="iconfont home_ico">&#xe719;</i>';
		} else {
			$("#workStatusDiv").removeClass();
			$("#workStatusDiv").addClass("home_button mr4p");
			htmlStr = '<label class="hometext" onclick="chgWorkStatus(0);">开始接单</label><i onclick="chgWorkStatus(0);" class="iconfont home_ico">&#xe712;</i>';
		}
		$("#workStatusDiv").html(htmlStr);
	}
	function chgWorkStatus(lockFlag) {
		var driverUuid = getCookie("driverUuid");
		$.ajax({
			type : 'POST',
			url : _global.serverHost + '/driver/chgLockFlag.htm',
			dataType : "json",
			data : {
				'driverUuid' : driverUuid,
				'lockFlag' : lockFlag
			},
			success : function(data) {
				if (data.outResult == '1') {
					console.log("====" + JSON.stringify(data));
					genWorkStatus(data.lockFlag);
				} else {
					alert(data.outResultReason);
				}
			}
		});
	}

	function quickBill() {
		var lnglatXY = [ 121.319308, 31.240986 ]; //已知点坐标
		//如果获取不到的地址的话，默认一个经纬度
		var llon = '121.319308';
		var llat = '31.240986';
		try {
			var positionStr = delegate.getCurrentLocation();
			if (positionStr != undefined && positionStr != null) {
				//'{lon=101,lat=102}'转化为'{lon:101,lat:102}'
				positionStr = positionStr.replace("=", ":").replace("=", ":");
				//string 转化为json
				var positionObj = eval('(' + positionStr + ')');
				llon = positionObj.lon;
				llat = positionObj.lat;
				if (llon != undefined && llon != null && llon != '') {
					lnglatXY = [ llon, llat ];
				}
			}
		} catch (e) {
			lnglatXY = [ 121.319308, 31.240986 ]; //已知点坐标 
			console.log("delegate.getCurrentLocation()不能读取当前地址经纬度");
		}
		var geocoder = new AMap.Geocoder({
			radius : 1000,
			extensions : "all"
		});
		geocoder.getAddress(lnglatXY, function(status, result) {
			console.log("====="+JSON.stringify(result));
			if (status === 'complete' && result.info === 'OK') {
				geocoder_CallBack(result);
			}
		});
		function geocoder_CallBack(result) {
			var a = result.regeocode.addressComponent;
			var aa = result.regeocode.pois;
			$("#startDistrictCode").val(a.adcode);
			$("#startAddr").val(aa[0].name);
			//$("#tipinput").val(aa[0].name);
			$("#startPCD").val(a.province + a.city + a.district);
			$("#startLocation").val(llon + ',' + llat);
			//$("#startAddrDesc").html(aa[0].name);
			//$("#startStreetDesc").html(a.street + a.streetNumber);
			$("#startStreet").val(a.street + a.streetNumber);
			console.log("====="+JSON.stringify(aa[0]));
		}
	}
	
</script>
</body>
</html>